package recommend

import (
	"context"
	"strconv"

	"mall/service/backend/api/internal/svc"
	"mall/service/backend/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type InitUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 初始Gorse 用户
func NewInitUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InitUserLogic {
	return &InitUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *InitUserLogic) InitUser() (*types.BackendDiagnoseResp, error) {
	for u := 1; u <= 50; u++ {
		err := l.CreateUserLogic(strconv.Itoa(u))
		if err != nil {
			return nil, err
		}
	}
	return nil, nil
}

func (l *InitUserLogic) CreateUserLogic(uid string) error {
	return l.svcCtx.GorseClient.CreateUser(
		l.svcCtx.Config.Query.GorseUrl,
		uid, "",
		"", "测试用户"+uid,
	)
}
